package com.ihtry.dao;

import com.ihtry.pojo.Admin;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AdminDao {
    /**
     * 登录
     */
    @Select("select * from admin where username = #{username} and password= #{password} ")
    public Admin login(Admin admin);

    /**
     * 注册
     */
    @Insert("insert into admin(username,password) values(#{username},#{password})")
    public boolean reg(Admin admin);

    /**
     * 查询全部用户
     */
    @Select("select * from admin order by id desc")
    public List<Admin> getAll();

    /**
     * 通过id查询
     */
    @Select("select * from admin where id = #{id}")
    public Admin getAdminById(Integer id);

    /**
     * 判断用户名是否重复
     */
    @Select("select * from admin where username = #{username}")
    public Admin getAdminByUsername(String username);

    /**
     * 修改用户
     */
    @Update("update admin set username = #{username} ,password = #{password} where id = #{id}")
    public boolean updateAdmin(Admin admin);

    /**
     * 根据id删除用户
     */
    @Delete("delete from admin where id = #{id}")
    public boolean deleteAdmin(Integer id);
}
